import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper'

let app: any = null;
const render = (container: any) => {
    app = createApp(App)
    app.use(router)
    app.mount(container ? container.querySelector('#app') : '#app')
}


const initQianKun = () => {
    renderWithQiankun({
        bootstrap() {
            console.log('微应用：bootstrap')
        },
        mount(props) {
            // 获取主应用传入数据
            console.log('微应用：mount', props)
            const { container } = props
            render(container)
        },
        unmount(props) {
            console.log('微应用：unmount', props)
            //离开销毁
            app.unmount()
        },
        update(props) {
            console.log('微应用：update', props)
        },
    })
}
// 判断是否使用 qiankun ，保证项目可以独立运行
qiankunWindow.__POWERED_BY_QIANKUN__ ? initQianKun() : render()